package com.welsy.authoring.command
{
	import mx.rpc.IResponder;
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.welsy.util.Comparator;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.events.FaultEvent;
	import mx.controls.Alert;
	import mx.collections.ICollectionView;
	import mx.collections.Sort;
	import mx.collections.SortField;
	import mx.utils.ArrayUtil;	
	import mx.collections.ArrayCollection;
	import com.welsy.authoring.event.hasIteraEvent;
	import com.welsy.authoring.business.hasIteraDelegate;
	import com.adobe.cairngorm.commands.SequenceCommand;
	import com.welsy.authoring.vo.course.pattern.CourseState;
	import com.welsy.authoring.model.CourseModelLocator;
	import com.welsy.authoring.vo.CourseVO;
	
	/**
	 * @version	$Revision: 1.1 $
	 */
	public class hasIteraCommand implements ICommand, IResponder
	{
	  	public function hasIteraCommand()
		{	 
		}
	
		public function execute( event : CairngormEvent ): void
		{
			var hasEvent:hasIteraEvent = hasIteraEvent( event );
			
			var delegate:hasIteraDelegate = new hasIteraDelegate( this );
			delegate.hasItera(hasEvent.courseID);			    			
		}
	
		public function result( event : Object ) : void
		{				
			var model : CourseModelLocator = CourseModelLocator.getInstance();
			model.courseEditing = false
			
			var resultlist:XMLList = XMLList(event.result)
			var result:String = XML(resultlist.child(0).child(0)).toString()
			
			if (result.toLowerCase() == "true") {   		
				Alert.show("Corso rimesso in bozza")	
				model.courseEditing = true
				//changeStatusCourses(model)
			}
			else
				Alert.show("Il corso non può essere rimesso in bozza perchè già associato a uno o più iter") 				
		}
		
		/* public function changeStatusCourses(model:CourseModelLocator):void
		{
			var acCourses:ArrayCollection = ArrayCollection(model.courses)
			var myCourse:CourseVO
			for each (myCourse in acCourses) {
				if (myCourse.id == model.selectedCourse.course.id){
					myCourse.state = CourseState.edit;
					break;
				}    				
			}
		} */
				
		public function fault( event : Object ) : void
		{
			var faultEvent : FaultEvent = FaultEvent( event );
			Alert.show("Course could not be retrieved!" );
		}
	}

}